package xxd
import grails.util.BuildSettings
import org.springframework.core.io.ClassPathResource
import org.springframework.core.io.support.PropertiesLoaderUtils
import sysUtil.SysCommUtil
import xdTool.XdTableCfg
import xdTool.XdWidgetPanel


class SpecialTest01Controller {


    def buildSettings = BuildSettings.newInstance()
    def index() {
        def dir = grailsApplication.getMainContext().servletContext.getRealPath("")
        println "${buildSettings.userHome}"
        new File("${buildSettings.userHome}\\dataFile").mkdirs()
        render "grailsHome:${buildSettings.baseDir}"
    }


    def a = {
        XdTableCfg xdTableCfg = XdTableCfg.first()
        List layUiCols = xdTableCfg.getLayUiColsModel(null)
        def rowSize = layUiCols.size()
        def colSize = layUiCols?.first()?.colspan?.sum()?:0

        //1.遍历每行数据(rowIndex)
        //2.求出每个单元格在表格中的行列索引(rowIndex,colIndex) ，
        //  ---如果有合并单元格，则求出单元格合并的范围：CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol)
        //  --------1.如果合并单元格是列colspan>1,则创建的下一个单元格的列索引=当前Cell的colIndex+ 当前Cell的colspan
        //  -----------------------------------1.1如果是列，则从该单元格的下一行开始，执行第1步
        //  --------2.如果合并单元格式行rowspan>1,则创建的下一个单元格的行索引=当前cell的rowIndex+当前cell的rowspan
        //  -----------------------------------2.1.如果是行，则从该

    }

    /**
     * B方式，通过列来索引行
     */

    def sysDBUtilService

    def b(){

        def XdWidgetPanel xdWidgetPanel = XdWidgetPanel.findByName("打发")

        //sysDBUtilService.getGroovySqlInstanceById(dataSourceId)
        params.dataPanelId = xdWidgetPanel.dataPanelId
        params.dataSql = SysCommUtil.Clob2String(xdWidgetPanel.dataSql)
        def sql = sysDBUtilService.getPanelDataSqlByType(xdWidgetPanel.dataType,params)

        XdTableCfg xdTableCfg = XdTableCfg.get(xdWidgetPanel.dataId)

        def db = sysDBUtilService.getGroovySqlInstanceById(xdWidgetPanel?.dataSourceId)
        def data  = sysDBUtilService.pageAllResult(sql,db)

    }


    def c(){
        println grailsApplication.config
        //读取配置文件
        def property = PropertiesLoaderUtils.loadProperties(new ClassPathResource("dataSource.properties"))
        render   grailsApplication.config
    }


    //1.注入service:myBatisUtilService
    //2.在mapper文件中配置sql
    //3.调用myBatisUtilService.getSqlSession()，执行相应SQL
    def myBatisUtilService
    def d(){
        render myBatisUtilService.getSqlSession().selectList("XdSysAdminMapper.sysParams")
    }
}
